package com.cangxuan.manage.controller;

import com.cangxuan.manage.annotation.Check;
import com.cangxuan.manage.annotation.check.Max;
import com.cangxuan.manage.annotation.check.NotNull;
import com.cangxuan.manage.bean.Page;
import com.cangxuan.manage.dao.IRegistrationDao;
import com.cangxuan.manage.entity.Goods;
import com.cangxuan.manage.entity.Order;
import com.cangxuan.manage.entity.Registration;
import com.cangxuan.manage.service.IRegistrationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "挂单相关接口")
@RestController
@RequestMapping("registration")
public class RegistrationController extends BaseController{
    IRegistrationService iRegistrationService;
    @Autowired
    public void setiRegistrationService(IRegistrationService iRegistrationService) {
        this.iRegistrationService = iRegistrationService;
    }

    @Data
    @ApiModel("二级市场挂单实体")
    public static class registrationBody{
        @ApiModelProperty("藏品名称")
        String name;
        @ApiModelProperty("用户id")
        Integer userId;
    }

    @PostMapping("rgt")
    @ApiOperation("二级市场挂单")
    public Object get(@RequestBody registrationBody registrationBody) {
        List<Registration> registrationList = iRegistrationService.list(registrationBody.getName()
                ,registrationBody.getUserId());
        return success(registrationList);
    }

    @PostMapping("remove")
    @ApiOperation("删除挂单")
    public Object save(@RequestParam int id) {
        iRegistrationService.save(id);
        return success();
    }
    @Data
    @ApiModel("二级市场挂单分页查询body")
    public static class RegistrationPageBody{
        @ApiModelProperty("页码，从1开始")
        @NotNull(message = "请传递pageIndex")
        Integer pageIndex;
        @ApiModelProperty("页大小，就是每页查询的数量，最大为50条")
        @Max(value = 50, message = "pageSize不能大于50")
        Integer pageSize = 10;
        @ApiModelProperty("藏品名称")
        String name;
        @ApiModelProperty("用户Id")
        Integer userId;
    }

    /**
     *二级市场挂单分页
     * @param registrationPageBody
     * @return
     */
    @PostMapping
    @ApiOperation("二级市场挂单分页查询")
    public Object page(@Check @RequestBody RegistrationPageBody registrationPageBody) {
        Page<Registration> registrationPage = iRegistrationService.page(registrationPageBody.getPageIndex(),
                registrationPageBody.getPageSize(),
                registrationPageBody.getName(),
                registrationPageBody.getUserId());
        return success(registrationPage);
    }




}
